# -*- coding: UTF-8 -*-
__author__ = 'kidozh'

from . import base
import datetime
import bcrypt
from exceptions import ImproperlyPassword
from peewee import *
from db.models import baseModel
from playhouse.fields import PasswordField


class admin(baseModel):
    username = CharField(unique=True)
    nickname = CharField(max_length=20,help_text=u'将会对外显示',null=True)
    password = PasswordField(help_text=u'采用bcrypt加密')

    # time
    register_time = DateTimeField(default=datetime.datetime.now)

    # permissions
    isStaff = BooleanField(default=False)
    isAdmin = BooleanField(default=False)

    def authPassword(self,password):
        return bcrypt.checkpw(password.encode('utf-8'), self.password.encode('utf-8')) and len(password) > 8



